home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / perl5 / GnuPG / Key.pm < prev    next >
Encoding:
Perl POD Document  |  2010-06-05  |  6.1 KB  |  274 lines

  1. #  Key.pm
  2. #    - providing an object-oriented approach to GnuPG keys
  3. #
  4. #  Copyright (C) 2000 Frank J. Tobin <ftobin@cpan.org>
  5. #
  6. #  This module is free software; you can redistribute it and/or modify it
  7. #  under the same terms as Perl itself.
  8. #
  9. #  This program is distributed in the hope that it will be useful,
  10. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. #
  13. #  $Id: Key.pm,v 1.10 2001/12/10 01:29:27 ftobin Exp $
  14. #
  15.  
  16. package GnuPG::Key;
  17. use Any::Moose;
  18. with qw(GnuPG::HashInit);
  19.  
  20. has [
  21.     qw( length
  22.         algo_num
  23.         hex_id
  24.         hex_data
  25.         creation_date
  26.         expiration_date
  27.         creation_date_string
  28.         expiration_date_string
  29.         fingerprint
  30.         usage_flags
  31.         )
  32.     ] => (
  33.     isa => 'Any',
  34.     is  => 'rw',
  35.     );
  36.  
  37. has [
  38.      qw(
  39.          signatures
  40.          revokers
  41.          revocations
  42.          pubkey_data
  43.       )] => (
  44.     isa       => 'ArrayRef',
  45.     is        => 'rw',
  46.     default   => sub { [] },
  47. );
  48.  
  49. sub push_signatures {
  50.     my $self = shift;
  51.     push @{ $self->signatures }, @_;
  52. }
  53.  
  54. sub push_revocations {
  55.     my $self = shift;
  56.     push @{ $self->revocations }, @_;
  57. }
  58.  
  59. sub push_revokers {
  60.     my $self = shift;
  61.     push @{ $self->revokers }, @_;
  62. }
  63.  
  64. sub short_hex_id {
  65.     my ($self) = @_;
  66.     return substr $self->hex_id(), -8;
  67. }
  68.  
  69. sub compare {
  70.   my ($self, $other, $deep) = @_;
  71.  
  72.   my @string_comparisons = qw(
  73.     length
  74.     algo_num
  75.     hex_id
  76.     creation_date
  77.     creation_date_string
  78.     usage_flags
  79.                            );
  80.  
  81.   my $field;
  82.   foreach $field (@string_comparisons) {
  83.     return 0 unless $self->$field eq $other->$field;
  84.   }
  85.  
  86.   my @can_be_undef = qw(
  87.     hex_data
  88.     expiration_date
  89.     expiration_date_string
  90.   );
  91.   foreach $field (@can_be_undef) {
  92.     return 0 unless (defined $self->$field) == (defined $other->$field);
  93.     if (defined $self->$field) {
  94.       return 0 unless $self->$field eq $other->$field;
  95.     }
  96.   }
  97.   my @objs = qw(
  98.     fingerprint
  99.   );
  100.   foreach $field (@objs) {
  101.     return 0 unless $self->$field->compare($other->$field, $deep);
  102.   }
  103.  
  104.   if (defined $deep && $deep) {
  105.     my @lists = qw(
  106.       signatures
  107.       revokers
  108.       revocations
  109.                  );
  110.     my $i;
  111.     foreach my $list (@lists) {
  112.       return 0 unless @{$self->$list} == @{$other->$list};
  113.       for ( $i = 0; $i < scalar(@{$self->$list}); $i++ ) {
  114.         return 0
  115.           unless $self->$list->[$i]->compare($other->$list->[$i], $deep);
  116.       }
  117.     }
  118.  
  119.     return 0 unless @{$self->pubkey_data} == @{$other->pubkey_data};
  120.     for ( $i = 0; $i < scalar(@{$self->pubkey_data}); $i++ ) {
  121.       return 0 unless (0 == $self->pubkey_data->[$i]->bcmp($other->pubkey_data->[$i]));
  122.     }
  123.   }
  124.   return 1;
  125. }
  126.  
  127. __PACKAGE__->meta->make_immutable;
  128.  
  129. 1;
  130.  
  131. __END__
  132.  
  133. =head1 NAME
  134.  
  135. GnuPG::Key - GnuPG Key Object
  136.  
  137. =head1 SYNOPSIS
  138.  
  139.   # assumes a GnuPG::Interface object in $gnupg
  140.   my @keys = $gnupg->get_public_keys( 'ftobin' );
  141.  
  142.   # now GnuPG::PublicKey objects are in @keys
  143.  
  144. =head1 DESCRIPTION
  145.  
  146. GnuPG::Key objects are generally not instantiated on their
  147. own, but rather used as a superclass of GnuPG::PublicKey,
  148. GnuPG::SecretKey, or GnuPG::SubKey objects.
  149.  
  150. =head1 OBJECT METHODS
  151.  
  152. =head2 Initialization Methods
  153.  
  154. =over 4
  155.  
  156. =item new( I<%initialization_args> )
  157.  
  158. This methods creates a new object.  The optional arguments are
  159. initialization of data members.
  160.  
  161. =item hash_init( I<%args> ).
  162.  
  163.  
  164. =item short_hex_id
  165.  
  166. This returns the commonly-used short, 8 character short hex id
  167. of the key.
  168.  
  169. =item compare( I<$other>, I<$deep> )
  170.  
  171. Returns non-zero only when this Key is identical to the other
  172. GnuPG::Key.  If $deep is present and non-zero, the key's associated
  173. signatures, revocations, and revokers will also be compared.
  174.  
  175. =back
  176.  
  177. =head1 OBJECT DATA MEMBERS
  178.  
  179. =over 4
  180.  
  181. =item length
  182.  
  183. Number of bits in the key.
  184.  
  185. =item algo_num
  186.  
  187. They algorithm number that the Key is used for.
  188.  
  189. =item usage flags
  190.  
  191. The Key Usage flags associated with this key, represented as a string
  192. of lower-case letters.  Possible values include: (a) authenticate, (c)
  193. certify, (e) encrypt, and (s) sign.
  194.  
  195. A key may have any combination of them in any order.  In addition to
  196. these letters, the primary key has uppercase versions of the letters
  197. to denote the _usable_ capabilities of the entire key, and a potential
  198. letter 'D' to indicate a disabled key.
  199.  
  200. See "key capabilities" DETAILS from the GnuPG sources for more
  201. details.
  202.  
  203. =item hex_data
  204.  
  205. The data of the key.  WARNING: this seems to have never been
  206. instantiated, and should always be undef.
  207.  
  208. =item pubkey_data
  209.  
  210. A list of Math::BigInt objects that correspond to the public key
  211. material for the given key (this member is empty on secret keys).
  212.  
  213. For DSA keys, the values are: prime (p), group order (q), group generator (g), y
  214.  
  215. For RSA keys, the values are: modulus (n), exponent (e)
  216.  
  217. For El Gamal keys, the values are: prime (p), group generator (g), y
  218.  
  219. For more details, see: http://tools.ietf.org/html/rfc4880#page-42
  220.  
  221. =item hex_id
  222.  
  223. The long hex id of the key.  This is not the fingerprint nor
  224. the short hex id, which is 8 hex characters.
  225.  
  226. =item creation_date_string
  227.  
  228. =item expiration_date_string
  229.  
  230. Formatted date of the key's creation and expiration.  If the key has
  231. no expiration, expiration_date_string will return undef.
  232.  
  233. =item creation_date
  234.  
  235. =item expiration_date
  236.  
  237. Date of the key's creation and expiration, stored as the number of
  238. seconds since midnight 1970-01-01 UTC.  If the key has no expiration,
  239. expiration_date will return undef.
  240.  
  241. =item fingerprint
  242.  
  243. A GnuPG::Fingerprint object.
  244.  
  245. =item signatures
  246.  
  247. A list of GnuPG::Signature objects embodying the signatures on this
  248. key.  For subkeys, the signatures are usually subkey-binding
  249. signatures.  For primary keys, the signatures are statements about the
  250. key itself.
  251.  
  252. =item revocations
  253.  
  254. A list of revocations associated with this key, stored as
  255. GnuPG::Signature objects (since revocations are a type of
  256. certification as well).  Note that a revocation of a primary key has a
  257. different semantic meaning than a revocation associated with a subkey.
  258.  
  259. =item revokers
  260.  
  261. A list of GnuPG::Revoker objects associated with this key, indicating
  262. other keys which are allowed to revoke certifications made by this
  263. key.
  264.  
  265. =back
  266.  
  267. =head1 SEE ALSO
  268.  
  269. L<GnuPG::Fingerprint>,
  270. L<GnuPG::Signature>,
  271. L<GnuPG::Revoker>,
  272.  
  273. =cut
  274.